//将方法函数定义好并暴露
export const getListData=(data)=>{
    return {
        type:"GETNEWS",
        data
    }
}

//获取所有的news
export function getNews(params={page:1}){
    return dispatch=>{
        var start =20*(params.page-1);
        var url='http://localhost:3000/news/list';
        var data='page='+params.page;
        return fetch(url,{
            method:'post',
            headers:{
                'Content-Type':'application/x-www-form-urlencoded'
            },
            body:data
        })
        .then(res=>{
            return res.json()
        })
        .then((data)=>{
            console.log(data)
            dispatch(getListData(data));
        })
    }
}







